<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/web/page/head.jsp" %>
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field" style="margin: 20px;padding:15px;">
        <legend>部门维护--修改信息</legend>
    <form class="layui-form" lay-filter="formA" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-inline">
                <input type="text" name="code" readonly lay-verify="required" placeholder="请输入编号" autocomplete="off"
                    class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" placeholder="请输入名称" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input type="text" name="del" placeholder="请输入电话" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline">
                <input type="button" class="layui-btn" lay-submit lay-filter="upd" value="确定" />
                <input type="button" class="layui-btn" onclick="closeThis()" value="取消" />
            </div>
        </div>
        <input type="hidden" name="action" value="upd" />
    </form>
    </fieldset>
    
    <script type="text/javascript">
    var layer = layui.layer;
    var $ = layui.jquery;
    var laytpl = layui.laytpl;
    var element = layui.element;
    var form = layui.form
    element.render();
    var code = '<%=request.getParameter("code")%>';
    init();
    function init(){
    	var code = '<%=request.getParameter("code")%>';
    	$.ajax({
    		url:"<%=app %>/DepartmentServlet",
    		data:{action:'get',code:code},
    		dataType:'json',
    		type:'post',
    		success:function(data){
    			console.log(data);
    			form.val("formA",{name:data.name,code:data.code,del:data.del})
// 				$("input[name='name']").val(data.name);
// 				$("input[name='code']").val(data.code);
// 				$("input[name='del']").val(data.del);
    		}
    	})
    	
    }
    function closeThis(){
    	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    	parent.layer.close(index); //再执行关闭   
    }
    form.on("submit(upd)",function(data){
    	$.ajax({
    		url:"<%=app %>/DepartmentServlet",
    		data:data.field,
    		dataType:'text',
    		type:'post',
    		success:function(data){
    			console.log(data)
    			if(data==1){
    				layer.msg('修改成功',closeThis);
    			}else{
    				layer.msg('修改失败');
    			}
    		}
    	})
    })
    </script>
</body>
</html>